VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Shrink long file name, like c:\program Files\...\...\yourfile.txt

by Andrey (3 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 28th June 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Shrink long file name, like c:\program Files\...\...\yourfile.txt

Rate Shrink long file name, like c:\program Files\...\...\yourfile.txt



Dim strTemp As String, strPart1 As String, strPart2 As String
Dim strFileOnly As String
Dim strSearchFor As String

    strSearchFor = "\" & String(3, ShrinkChar) & "\"
    strFileOnly = Right(FileName, Len(FileName) - InStrRev(FileName, "\"))
    
    Do While Len(FileName) > FileNameSizeLimit
        If InStr(1, FileName, strSearchFor) Then
            strPart1 = Left(FileName, InStr(1, FileName, strSearchFor) - 1)
            If Right(strPart1, 1) = ":" Then Exit Do
            strPart1 = Left(strPart1, InStrRev(strPart1, "\") - 1)
            strPart2 = Right(FileName, Len(FileName) - InStr(1, FileName, strSearchFor))
            FileName = strPart1 & strSearchFor & strPart2
        Else
            strPart1 = Left(FileName, Len(FileName) - Len(strFileOnly) - 1)
            strPart1 = Left(strPart1, InStrRev(strPart1, "\") - 1)
            FileName = strPart1 & strSearchFor & strFileOnly
        End If
        DoEvents
    Loop
    SrinkFileName = FileName
  
End Function

Download this snippet    Add to My Saved Code

Shrink long file name, like c:\program Files\...\...\yourfile.txt Comments

No comments have been posted about Shrink long file name, like c:\program Files\...\...\yourfile.txt. Why not be the first to post a comment about Shrink long file name, like c:\program Files\...\...\yourfile.txt.

Post your comment

Subject:
Message:
0/1000 characters